import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_project/config/theme_color.dart';
import 'package:get/get.dart';

class CommonAppWidget {
  CommonAppWidget._();

  static navAppBar(
      {String title = '',
      Widget? childWidget,
      List<Widget>? rightActions,
      Color? bgColor,
      double elevation = 0,
      Color? appBarColor,
      String? iconStr,
      Widget? titleWidget,
      bool isHiddenLeftArrow = false,
      Color? leftIconColor,
      PreferredSizeWidget? bottom,
      Function? backAction}) {
    return Scaffold(
      backgroundColor: bgColor ?? ThemeColor.mainBgColor,
      appBar: AppBar(
        backgroundColor: appBarColor ?? Colors.white,
        title: titleWidget ??
            Text(
              title,
              style: TextStyle(
                  fontSize: 18,
                  color: ThemeColor.textColor,
                  fontWeight: FontWeight.w500),
            ),
        centerTitle: true,
        elevation: elevation,
        //backgroundColor: appBarColor ?? Colors.white,
        actions: rightActions,
        bottom: bottom,
        leading: isHiddenLeftArrow
            ? const SizedBox()
            : leftArrowWidget(iconStr,
                isHiddenLeftArrow: isHiddenLeftArrow,
                backAction: backAction,
                leftIconColor: leftIconColor),
      ),
      body: childWidget,
    );
  }

  static navTitleBar(
      {String title = '',
      Widget? childWidget,
      List<Widget>? rightActions,
      Color? bgColor,
      double elevation = 0,
      Color? appBarColor,
      String? iconStr,
      Widget? titleWidget,
      bool isHiddenLeftArrow = false,
      Color? leftIconColor,
      PreferredSizeWidget? bottom,
      Function? backAction}) {
    return AppBar(
      title: titleWidget ??
          Text(
            title,
            style: TextStyle(
                fontSize: 18,
                color: ThemeColor.textColor,
                fontWeight: FontWeight.w500),
          ),
      centerTitle: true,
      elevation: elevation,
      backgroundColor: appBarColor ?? Colors.white,
      actions: rightActions,
      bottom: bottom,
      leading: leftArrowWidget(iconStr,
          isHiddenLeftArrow: isHiddenLeftArrow,
          backAction: backAction,
          leftIconColor: leftIconColor),
    );
  }

  static leftArrowWidget(String? iconStr,
      {bool isHiddenLeftArrow = false,
      Function? backAction,
      Color? leftIconColor}) {
    return isHiddenLeftArrow
        ? null
        : UnconstrainedBox(
            child: CupertinoButton(
              padding: EdgeInsets.zero,
              onPressed: () {
                if (backAction != null) {
                  backAction();
                } else {
                  Get.back();
                }
              },
              child: Image.asset(
                iconStr ?? 'assets/images/left_back_arrow.png',
                width: 16,
                color: leftIconColor ?? Colors.black,
              ),
            ),
          );
  }
}
